package cn.smxy.admin.service.impl;

import cn.smxy.admin.service.CategoryService;
import cn.smxy.client.CategoryClient;
import cn.smxy.param.FamilyFuzzyParam;
import cn.smxy.param.PageParam;
import cn.smxy.pojo.Category;
import cn.smxy.pojo.PlantFamily;
import cn.smxy.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryClient categoryClient;

    /**
     * 添加种群
     *
     * @param category
     * @return
     */
    @Override
    public R add(Category category) {
        return categoryClient.add(category);
    }

    /**
     * 分页展示种群
     *
     * @param pageParam
     * @return
     */
    @Override
    public R page(PageParam pageParam) {
        return categoryClient.page(pageParam);
    }

    /**
     * 修改种群
     *
     * @param category
     * @return
     */
    @Override
    public R update(Category category) {
        return categoryClient.update(category);
    }

    /**
     * 删除种群
     *
     * @param categoryId
     * @return
     */
    @Override
    public R remove(Long categoryId) {
        return categoryClient.remove(categoryId);
    }

    /**
     * 返回种群对应科名列表
     *
     * @param categoryId
     * @return
     */
    @Override
    public R show(Long categoryId) {
        return categoryClient.show(categoryId);
    }

    /**
     * 添加科名
     *
     * @param plantFamily
     * @return
     */
    @Override
    public R addFamily(PlantFamily plantFamily) {
        return categoryClient.addFamily(plantFamily);
    }

    /**
     * 返回属名列表
     *
     * @param familyId
     * @return
     */
    @Override
    public R genusShow(Long familyId) {
        return categoryClient.genusShow(familyId);
    }

    /**
     * 添加属名
     *
     * @param plantFamily
     * @return
     */
    @Override
    public R addGenus(PlantFamily plantFamily) {
        if(plantFamily.getParentId() == null && plantFamily.getFamilyId() != null) {
            plantFamily.setParentId(plantFamily.getFamilyId());
            plantFamily.setFamilyId(null);
        }
        return categoryClient.addGenus(plantFamily);
    }

    /**
     * 删除科属
     *
     * @param familyId
     * @return
     */
    @Override
    public R familyRemove(Long familyId) {
        return categoryClient.familyRemove(familyId);
    }

    /**
     * 按条件分页查询科属
     *
     * @param familyFuzzyParam 种群id 科属id 分页参数 模糊查询科属名
     * @return
     */
    @Override
    public R fuzzy(FamilyFuzzyParam familyFuzzyParam) {
        return categoryClient.fuzzy(familyFuzzyParam);
    }
}
